package com.webcat.controller;

import com.alibaba.fastjson.JSONObject;
import com.webcat.dify.kb.DifyKBClient;
import com.webcat.dify.kb.KBResponse;
import com.webcat.dify.kb.entity.KnowledgeBase;
import com.webcat.entity.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/kb")
@Slf4j
public class KBController {

    @Resource
    private DifyKBClient difyKBClient;

    @GetMapping("/getKBList")
    public Response<List<JSONObject>> getKBList() {
        List<KnowledgeBase> knowledgeBaseList = (List<KnowledgeBase>)difyKBClient.getKnowledgeBase().getData();
        List<JSONObject> list = knowledgeBaseList.stream().map(knowledgeBase -> {
            JSONObject kbJson = new JSONObject();
            kbJson.put("id", knowledgeBase.getId());
            kbJson.put("name", knowledgeBase.getName());
            return kbJson;
        }).toList();
        return Response.success(list);
    }
}
